#ifndef NATRIUM_UTIL_THREADPOOL_H
#define NATRIUM_UTIL_THREADPOOL_H

#include "stdafx.h"

namespace natrium {
	/*
	 * Typically, using this threadpool involves creating a threadsafe
	 * list of jobs and a lambda that, in a loop, fetches work from the list
	 * until the list is empty
	 */

	namespace util {
		typedef std::function<void()> Task;

		class ThreadPool {
		public:
			ThreadPool(Task t, unsigned int numThreads = 0); //0 means autodetect
			~ThreadPool(); //by default this joins all threads

			void join(); //wait for all tasks to complete
			void detachAll(); //detach all threads

		private:
			bool mCompleted;
			std::vector<std::thread> mPool;
		};
	}
}

#endif
